<?php
/**
 *
 */

  $name=$_POST["name"]; 
  $passowrd=$_POST["password"];
  $areaid = $_POST["areaid"];
  $mbk_pos = $_POST["mbk_pos"];
  $mbk_pwd = $_POST["mbk_pwd"];

if (!$name || $areaid<0){

    echo "-2";
    exit(); 
 
}

$parameters = array(
        'areaid' => $areaid,
        'username' => $name,
        'password' =>$passowrd,
        'password_encrypted' => 1,
        'mbk_pos' => $mbk_pos,
        'mbk_pwd' => $mbk_pwd,
        'ip' => '127.0.0.1',
        'mac' => 'A5:B6:77:D9:25:C1',
        'returnonlinetime'=>'1'
        );
$token = NULL;

//third party login
$req = somreq();
$req->signRequest($sig_method, $consumer, $token);

$response = $req->request();
if ($response === false || $response['code'] != 200) {
    echo "-1";
    exit();
}
$result = $response['body'];

$userinfo = json_decode($result);

if($userinfo)
{
  if($userinfo->status==0)
  {
    $serverdata=$userinfo->data->userid.";".$userinfo->data->username.";".$userinfo->data->prevented.";".$userinfo->data->onlinetime.";".$userinfo->data->token.";".time();//还少一个onlinetime,等gas修改完再处理
    $privkey = openssl_get_privatekey(file_get_contents('../key/loginagent_rsa.prv'));
    openssl_sign($serverdata,$signature,$privkey);
    openssl_pkey_free($privkey);

    //$data = $userinfo->status."|".$serverdata;
    $serverbundle= $signature.$serverdata;
    $data = $userinfo->status."|".bin2hex($serverbundle);
    echo $data;
  }
  else
  {
    echo $userinfo->status;
  }
}
else
{
  echo "-1";
}

exit();


?>
